package net.zjitc;

import net.zjitc.ex01.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by Administrator on 2017/11/1.
 */
public class TestTwo {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        //通过名称获得类对象
        Class clazz = Class.forName("net.zjitc.ex01.Person");
        Person person = (Person) clazz.newInstance();

        Constructor[] constructor = clazz.getConstructors();
        for (Constructor c:constructor) {
            System.out.println(c);
        }

        Method method = clazz.getMethod("speck",String.class,int.class);
        method.invoke(person,"xw",50);

        System.out.println(person);
    }
}
